home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / bipl.zip / PROGS.ZIP / ILNKXREF.ICN < prev    next >
Text File  |  1992-12-30  |  3KB  |  105 lines

  1. #############################################################################
  2. #
  3. #    File:     ilnkxref.icn
  4. #
  5. #    Subject:  Program to produce Icon link cross reference
  6. #
  7. #    Author:   Robert J. Alexander
  8. #
  9. #    Date:     April 25, 1990
  10. #
  11. ###########################################################################
  12. #
  13. #  Utility to create cross reference of library files used in Icon
  14. #  programs (i.e., those files named in "link" declarations).
  15. #
  16. #    ilnkxref [-options] <icon source file>...
  17. #
  18. #    options:
  19. #
  20. #        -p    sort by "popularity"
  21. #        -v    report progress information
  22. #
  23. ############################################################################
  24. #
  25. #  Requires: UNIX
  26. #
  27. ############################################################################
  28. #
  29. #  Links: wrap, options, isort
  30. #
  31. ############################################################################
  32.  
  33. link wrap,options,isort
  34.  
  35. procedure main(arg)
  36. local comma, f, fill, fn, head, heads, i, libname, line, linesize, maxfile,
  37.    maxlib, opt, p, popularity, proctable, root, sep, spaces, verbose, x
  38.    #
  39.    #  Initialize
  40.    #
  41.    opt := options(arg,"pv")
  42.    popularity := opt["p"]    # sort by popularity
  43.    verbose := opt["v"]        # report progress
  44.    if *arg = 0 then {
  45.       p := open("ls *.icn","rp")
  46.       while put(arg,read(p))
  47.       close(p)
  48.       }
  49.    spaces := ' \t'
  50.    sep := ' \t,'
  51.    proctable := table()
  52.    maxlib := maxfile := 0
  53.    #
  54.    # Gather information from files.
  55.    #
  56.    every fn := !arg do {
  57.       if \verbose then write(&errout,"File: ",fn)
  58.       f := open(fn) | stop("Can't open ",fn)
  59.       i := 0
  60.       every i := find("/",fn)
  61.       root := fn[1:find(".",fn,i + 1) | 0]
  62.       comma := &null
  63.       while line := read(f) do {
  64.      line ? {
  65.         tab(many(spaces))
  66.         if \comma | ="link " then {
  67.            if \verbose then write(&errout,"    ",line)
  68.            comma := &null
  69.            tab(many(spaces))
  70.            until pos(0) | match("#") do {
  71.           libname := tab(upto(sep) | 0)
  72.           put(\proctable[libname],root) | (proctable[libname] := [root])
  73.           maxlib <:= *libname
  74.           maxfile <:= *root
  75.           tab(many(spaces))
  76.           comma := &null
  77.           if comma := ="," then tab(many(spaces))
  78.           }
  79.            }
  80.         }
  81.      }
  82.       close(f)
  83.       }
  84.    #
  85.    #  Print the cross reference table.
  86.    #
  87.    write()
  88.    proctable := sort(proctable)
  89.    if \popularity then proctable := isort(proctable,popproc)
  90.    every x := !proctable do {
  91.       head := left(x[1],maxlib + 3)
  92.       heads := [left("(" || *x[2] || ")",maxlib + 3),
  93.             fill := repl(" ",*head)]
  94.       linesize := 78 - *head
  95.       every x := !sort(x[2]) do
  96.      if write(head,wrap(left(x,maxfile + 2),linesize)) then
  97.         head := get(heads)
  98.       write(head,wrap())
  99.       }
  100. end
  101.  
  102. procedure popproc(x)
  103.   return -*x[2]
  104. end
  105.